package cn.maihe.elg.operation.utils;

import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;

/**
 * @Description
 * @Author caixh
 * @Date 2021/8/5.
 */
public class AliyunOcrHelper extends ApacheHttpClient {

    @Override
    public void init(HttpClientBuilderParams httpClientBuilderParams){
        httpClientBuilderParams.setScheme(Scheme.HTTPS);
        super.init(httpClientBuilderParams);
    }

    public ApiResponse ocrSyncMode(byte[] body,String path){
        ApiRequest request = new ApiRequest(HttpMethod.POST_BODY,path,body);
        return sendSyncRequest(request);
    }

    public ApiResponse ocrSyncMode(String IMAGE_TYPE , String IMAGE ,String path){
        ApiRequest request = new ApiRequest(HttpMethod.POST_FORM,path);
        request.addParam("IMAGE_TYPE" , IMAGE_TYPE , ParamPosition.BODY , true);
        request.addParam("IMAGE" , IMAGE , ParamPosition.BODY , true);
        return sendSyncRequest(request);
    }
}
